#include <QApplication>
#include <QQmlApplicationEngine>

#include "QQuickViews/QQuickOffscreenWebView.h"
#include "QQuickViews/QQuickOffscreenEditText.h"
#include "utils/webviewutils.h"
#include "utils/utils.h"
#include "databasecreator.h"
#include "synccontroller.h"

int main(int argc, char *argv[])
{
    QAndroidQPAPluginGap::preloadJavaClasses();
    QAndroidOffscreenWebView::preloadJavaClasses();
    QAndroidOffscreenEditText::preloadJavaClasses();

    QApplication app(argc, argv);

    qmlRegisterType<QQuickAndroidOffscreenEditText>("SceneGraphRendering", 1, 0, "OffscreenEditText");
    qmlRegisterType<QQuickAndroidOffscreenWebView>("SceneGraphRendering", 1, 0, "OffscreenWebView");
    qmlRegisterType<WebviewUtils>("Utils", 1, 0, "WebviewUtils");
    qmlRegisterType<SyncController>("Utils", 1, 0, "SyncController");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/qml/MainLoader.qml")));

    DatabaseCreator c;
    QSqlError e = c.createDatabase();
    if(e.isValid()) {
        qDebug(e.text().toUtf8());
    }

    SyncController sync;
    sync.startSync();

    return app.exec();
}
